package com.xinghou.platform.util;

import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by qingshengzheng on 16/5/11.
 */
public class SolrUtil {






    public static String getSearchKey(HashMap<String,String> map) {
        StringBuffer sr = new StringBuffer();
        Iterator it = map.keySet().iterator();
        Boolean isFirst = true;
        while (it.hasNext()) {

            String key = it.next().toString();
            String value = map.get(key);
            if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
                if (!isFirst) sr.append(" AND ");
                sr.append(key).append(":").append(value);
                isFirst = false;
            }

        }
        if (StringUtils.isEmpty(sr.toString())) {
            sr.append("*:*");
        }
        return sr.toString();
    }
    public static String getOrSearchKey(HashMap<String,String> map) {
        StringBuffer sr = new StringBuffer();
        Iterator it = map.keySet().iterator();
        Boolean isFirst = true;
        while (it.hasNext()) {

            String key = it.next().toString();
            String value = map.get(key);
            if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
                if (!isFirst) sr.append(" OR ");
                sr.append(key).append(":").append(value);
                isFirst = false;
            }

        }
        if (StringUtils.isEmpty(sr.toString())) {
            sr.append("*:*");
        }
        return sr.toString();
    }

}
